package com.anXin.mall.service.impl;

import com.anXin.mall.mapper.MallMapper;
import com.anXin.mall.service.MallService;
import com.anXin.model.common.dtos.ResponseResult;
import com.anXin.model.mall.pojos.Mall;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class MallServiceImpl extends ServiceImpl<MallMapper, Mall> implements MallService {
    @Override
    public ResponseResult<Mall> getMall() {
        List<Mall> list = query().list();
        if(list.iterator().hasNext()){
            return ResponseResult.okResult(list.get(0));
        }else return ResponseResult.errorResult(500,"查询错误");

    }

    @Override
    public ResponseResult<String> updataMall(Mall mall) {
        if(mall.getId()!=null){
            updateById(mall);
        }else {
            save(mall);
        }

        return ResponseResult.okResult("更新成功");
    }
}
